<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item
              label="学号"
              >
              <a-input placeholder="请输入学号" v-decorator="['stuNo', {}]" />
            </a-form-item>

          </a-col>


          <a-col :md="6" :sm="24">
            <a-form-item
              label="录取日期"
            >
              <a-date-picker style="width:164px" showTime format="YYYY-MM-DD" v-decorator="[ 'enrollTime', {}]" />
            </a-form-item>
          </a-col>

          <!--<a-col :md="6" :sm="24">-->
          <!--<a-form-item-->
            <!--label="是否录取"-->
            <!--&gt;-->
            <!--&lt;!&ndash;<a-input placeholder="请输入录取情况" v-decorator="['enrollStatus', {}]" />&ndash;&gt;-->
            <!--<j-dict-select-tag  v-decorator="['enrollStatus', {}]" :triggerChange="true" placeholder="请选择"-->
                                <!--dictCode="xc_yes_no"/>-->
          <!--</a-form-item>-->
          <!--</a-col>-->

        </a-row>

        <a-row :gutter="24">

          <a-col :md="6" :sm="24">
            <a-form-item
              label="平台账号"

              >
              <a-input placeholder="请输入平台账号" v-decorator="['platformAcount', {}]" />
            </a-form-item>
          </a-col>


          <a-col :md="6" :sm="24">
            <a-form-item
              label="平台密码"
              >
              <a-input placeholder="请输入平台密码" v-decorator="['platformPwd', {}]" />
            </a-form-item>
          </a-col>
        </a-row>


        <a-row :gutter="24">

          <a-col :md="6" :sm="24">
            <a-form-item
              label="机考账号"
              >
              <a-input placeholder="请输入机考账号" v-decorator="['machineAcount', {}]" />
            </a-form-item>
          </a-col>


          <a-col :md="6" :sm="24">

            <a-form-item
              label="机考密码"

             >
              <a-input placeholder="请输入机考密码" v-decorator="['machinePwd', {}]" />
            </a-form-item>
          </a-col>
        </a-row>


        <a-row :gutter="24">




          <a-col :md="6" :sm="24" v-if="showGraduateTime">
            <a-form-item
              label="毕业时间"
            >
              <a-date-picker style="width:164px" showTime format="YYYY-MM-DD" v-decorator="[ 'graduateTime', {}]" />
            </a-form-item>
          </a-col>
        </a-row>



        <a-row :gutter="24">

          <a-form-item
            label="备注"
            >
            <a-textarea rows="5" placeholder="请输入备注" v-decorator="['remark', {}]" />
          </a-form-item>

        </a-row>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="所属学生"
          :hidden="hiding"
          hasFeedback>
          <a-input placeholder="请输入所属学生" v-decorator="['studentId', {'initialValue':this.mainId}]" />
        </a-form-item>


      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from 'moment'
  import JDate from '@/components/jeecg/JDate'
  import ATextarea from 'ant-design-vue/es/input/TextArea'

  export default {
    components: {
      ATextarea,
      JDate
    },
    name: 'PlatformModal',
    data() {
      return {
        title: '操作',
        visible: false,
        model: {},
        labelCol: { span: 7 },
        wrapperCol:  { span: 17 },
        moment,
        format: 'YYYY-MM-DD HH:mm:ss',
        disableSubmit: false,
        mainId: '',
        hiding: false,
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
        },
        url: {
          add: '/student/student/addPlatform',
          edit: '/student/student/editPlatform'
        },
        showGraduateTime:false
      }
    },
    created() {
    },
    methods: {
      add(mainId) {

        if (mainId) {
          this.edit({mainId}, '')
        } else {
          this.$message.warning('请选择一条数据')
        }
      },

      detail(record) {
        this.edit(record, 'd')
      },
      edit(record, v) {
        this.showGraduateTime=false
        console.log("vvv->",v)
        try{
          let mainId=record.mainId
        }catch (e) {
          this.$message.warning("暂无录取信息！")
        }



        if (v == 'e') {
          this.showGraduateTime=true
          this.hiding = false;
          this.disableSubmit = false;
        } else if (v == 'd') {
          this.hiding = false;
          this.disableSubmit = true;
        } else {
          this.hiding = true;
          this.disableSubmit = false;
        }
        this.form.resetFields();
        this.mainId = record.mainId;

        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'stuNo','platformAcount', 'platformPwd', 'machineAcount', 'machinePwd', 'enrollStatus', 'enrollTime', 'graduateTime', 'remark', 'createName', 'updateName', 'studentId', ))
          // 时间格式化
          this.form.setFieldsValue({ enrollTime: this.model.enrollTime ? moment(this.model.enrollTime) : null })
          this.form.setFieldsValue({ graduateTime: this.model.graduateTime ? moment(this.model.graduateTime) : null })
          this.form.setFieldsValue({enrollStatus:'1'})
        })
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.enrollTime = formData.enrollTime?formData.enrollTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.graduateTime = formData.graduateTime?formData.graduateTime.format('YYYY-MM-DD HH:mm:ss'):null;
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel() {
        this.close();
      }
    }
  }
</script>

<style scoped>

</style>
